package com.wing.cabinet.model.entity;

import java.io.Serializable;
import java.time.LocalDateTime;

import java.math.BigDecimal;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wing.mybatis.common.BaseEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 售刀柜领取/暂存柜上/暂存/维修/回收明细
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("cab_use_inventory_inout_detail")
public class UseInventoryInoutDetail extends BaseEntity<UseInventoryInoutDetail> implements Serializable {

    private static final long serialVersionUID = 1L;

    public enum Type implements IEnum<Integer> {

        /**
        * 暂存/维修/回收存入
        */
        in(1,"暂存/维修/回收存入"),
        /**
        * 领取
        */
        out(2,"领取"),

        returned(3,"归还"),

        loss(7,"报失");

        private int code;
        private String desc;

        Type(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }

        @JsonCreator
        public static Type jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (Type item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }


    }

    public enum BusinessType implements IEnum<Integer> {

        /**
         * 业务类型:cellCabReceive(1,售刀柜领取);repairOrderSign(2,维修订单签收)
         */
//        cellCabReceive(1,"售刀柜领取"),
//
//        tempStorage(2,"存入暂存柜"),
        /**
         * 领取
         */
//        repairOrderSign(3,"维修订单签收"),
//        importByExcel(4,"存入暂存柜");
        /**
         * 业务类型:cellCabReceive(1,售刀柜领取);repairOrderSign(2,维修订单签收)
         */
        cellCabOut(1,"售刀柜领新"),

        tempIn(2,"存入暂存柜"),
        /**
         * 领取
         */
        repairOrderSign(3,"维修订单签收"),

        tempOut(4,"暂存柜取出"),

        outByReturned(5,"归还仓库管理员"),

        cellCabOutByOldNew(6,"售刀柜领新(以旧换新)"),

        /**
         * 维修
         */
        repairIn(7,"维修存入"),
        /**
         * 回收
         */
        recycleIn(8,"报废存入"),


        repairOutByCheck(9,"盘验维修取出"),

        recycleOutByCheck(10,"盘验报废取出"),

        recycleInByOldNew(11,"以旧换新存入报废"),

        tempInByCheck(12,"盘验暂存存入"),

        tempOutByCheck(13,"盘验暂存取出"),

        tempOutByCheckLose(14,"盘验暂存缺失"),

        repairOutByCheckLose(15,"盘验维修缺失"),

        recycleOutByCheckLose(16,"盘验报废缺失"),

        tempInByOldNew(17,"以旧换新存入暂存"),

        repairInByOldNew(18,"以旧换新存入维修"),

        tempOutByCheckSpec(19,"盘验暂存产品规格不相符"),

        repairOutByCheckSpec(20,"盘验维修产品规格不相符"),

        recycleOutByCheckSpec(21,"盘验报废产品规格不相符"),

        importUseByExcel(22,"导入在用刀具"),

        virtualOutByCheck(23,"维修报废盘验为暂存取出"),

        newOut(24,"存刀柜新刀取出"),

        loss(31,"报失");

        private int code;
        private String desc;

        BusinessType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }

        @JsonCreator
        public static BusinessType jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (BusinessType item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 售刀柜领取/暂存柜上/暂存/维修/回收任务id
     */
    private Long inoutId;

    /**
     * 柜子id
     */
    private Long cabId;

    /**
     * sku id
     */
    private Long skuId;

    /**
     * 数量
     */
    private Integer quantity;

    /**
     * 企业id
     */
    private Long companyId;

    /**
     * 货道/库位id
     */
    private Long spaceId;

    /**
     * 操作类型
     */
    private Type type;

    /**
    * 操作类型描述
    */
    @TableField(exist = false)
    private String typeDesc;

    public String getTypeDesc() {
        return type == null ? null : type.getDesc();
    }

    /**
     * sku code
     */
    private String skuCode;

    /**
     * 柜子编码
     */
    private String cabCode;

    /**
     * 货道/货位编码
     */
    private String spaceCode;

    /**
     * 当前库存
     */
    private Integer quantityCurrent;

    /**
     * 变动后库存
     */
    private Integer quantityAfter;

    private BusinessType businessType;


    private String labelCode;

    /**
     * 企业编码
     */
    private String enterpriseCode;

    /**
     * 是否同步成功
     */
    private Integer isSyns;

    @TableField(exist = false)
    private String inoutUniqCode;

    /**
     * 同步时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime synsTime;

    private BigDecimal price;

    private BigDecimal total;

    /**
     * 企业端数据id
     */
    @TableField(exist = false)
    private Long idOfEnterpriseId;

    private Integer quantityProductCurrent;

    private Integer quantityProductAfter;

    private Long useInventoryUserId;
    /**
     * 渠道编号
     */
    private String channelCode;

    private String mainCabCode;

    private Integer quantityPack;

    private Integer quantityPackUnit;


    private Long packId;

    private String packName;

    private String unitName;
}
